//modified by gzz@20151016 for optimize begin
/*$(document).keypress(function(event)     
        {     
                if(event.keyCode == 32){ 
                     window.event.onkeydown=false;
                    return false;
        }   
});*/
$(document).keypress(function(event){
    if(window.event){
        if(event.target.id && "socialNo" == event.target.id){
            window.event.onkeydown=true;
            return true;
        }else if(32 == event.keyCode){
            window.event.onkeydown=false;
            return false;
        }
    }else if(event.which){
        if(event.target.id && "socialNo" == event.target.id){
            document.onkeydown=true;
            return true;
        }else if(32 == event.which){
            document.onkeydown=false;
            return false;
        }
    }
});
//modified by gzz@20151016 for optimize end
/**
 * 日期格式化
 * @param obj
 * @returns {Boolean}
 */
function dateFormat(obj) {
    var value = $(obj).val();
    if(value==""){
        return true;
    }
    if(!isNum(value)){
        $(obj).val("");
        $(obj).focus();
        return false;
    }
    
    value = value.replace(/\//g, "-");//支持2012/01/01格式
    if(value.indexOf('-')>=0){
        var temp=value.split('-');
        var dateTemp=temp[0];
        for(var i=1;i<temp.length;i++){
            if(temp[i].length==1){
                var addtemp=0+temp[i];
                dateTemp+=addtemp;
            }else{
                dateTemp+=temp[i];
            }
        }
        value=dateTemp;
    }
    value = value.replace(/\D/g, "");
      if(value.length == 8){
        var year = value.substr(0,4);
        var month = value.substr(4,2);
        var day = value.substr(6,2);
        var returndate = year+"-" + month +"-"+day ;
        returndate  = returndate.replace("--","-").replace("--","-");
        if(!isDate(returndate)){
            $(obj).val("");
            $(obj).focus();
            return false;
        }
        $(obj).val(returndate);
    }else if(value.length == 10||value.length == 9){
        if(!isDate(value)){
            $(obj).val("");
            $(obj).focus();
            return false;
        }
    }else{
        alert("您输入的日期格式不正确! 参考格式:YYYYMMDD或YYYY-MM-DD");
        $(obj).val("");
        $(obj).focus();
        return false;
    }
      return true;

}
var messages = {
        "admin.message.success": "操作成功",
        "admin.message.error": "操作错误",
        "admin.dialog.ok": "确定",
        "admin.dialog.cancel": "取消",
        "admin.dialog.deleteConfirm": "您确定要删除吗？",
        "admin.dialog.clearConfirm": "您确定要清空吗？",
        "admin.browser.title": "选择文件",
        "admin.browser.upload": "本地上传",
        "admin.browser.parent": "上级目录",
        "admin.browser.orderType": "排序方式",
        "admin.browser.name": "名称",
        "admin.browser.size": "大小",
        "admin.browser.type": "类型",
        "admin.browser.select": "选择文件",
        "admin.upload.sizeInvalid": "上传文件大小超出限制",
        "admin.upload.typeInvalid": "上传文件格式不正确",
        "admin.upload.invalid": "上传文件格式或大小不正确",
        "admin.validate.required": "必填",
        "admin.validate.email": "E-mail格式错误",
        "admin.validate.url": "网址格式错误",
        "admin.validate.date": "日期格式错误",
        "admin.validate.dateISO": "日期格式错误",
        "admin.validate.pointcard": "信用卡格式错误",
        "admin.validate.number": "只允许输入数字",
        "admin.validate.digits": "只允许输入零或正整数",
        "admin.validate.minlength": "长度不允许小于{0}",
        "admin.validate.maxlength": "长度不允许大于{0}",
        "admin.validate.rangelength": "长度必须在{0}-{1}之间",
        "admin.validate.min": "不允许小于{0}",
        "admin.validate.max": "不允许大于{0}",
        "admin.validate.range": "必须在{0}-{1}之间",
        "admin.validate.accept": "输入后缀错误",
        "admin.validate.equalTo": "两次输入不一致",
        "admin.validate.remote": "输入错误",
        "admin.validate.integer": "只允许输入整数",
        "admin.validate.positive": "只允许输入正数",
        "admin.validate.negative": "只允许输入负数",
        "admin.validate.decimal": "数值超出了允许范围",
        "admin.validate.pattern": "格式错误",
        "admin.validate.extension": "文件格式错误"
};

function isNum(str){
    var numReg = /\d+/;
    return numReg.test(str);
}

function message(code) {
    if (code != null) {
        var content = messages[code] != null ? messages[code] : code;
        if (arguments.length == 1) {
            return content;
        } else {
            if ($.isArray(arguments[1])) {
                $.each(arguments[1], function(i, n) {
                    content = content.replace(new RegExp("\\{" + i + "\\}", "g"), n);
                });
                return content;
            } else {
                $.each(Array.prototype.slice.apply(arguments).slice(1), function(i, n) {
                    content = content.replace(new RegExp("\\{" + i + "\\}", "g"), n);
                });
                return content;
            }
        }
    }
}
(function($) {

    var zIndex = 1000000;
    
    // 消息框
    var $message;
    var messageTimer;
    $.message = function() {
        var message = {};
        if ($.isPlainObject(arguments[0])) {
            message = arguments[0];
        } else if (typeof arguments[0] === "string" && typeof arguments[1] === "string") {
            message.type = arguments[0];
            message.content = arguments[1];
        } else {
            return false;
        }
        
        if (message.type == null || message.content == null) {
            return false;
        }
        
        if ($message == null) {
            $message = $('<div class="xxMessage"><div class="messageContent message' + message.type + 'Icon"><\/div><\/div>');
            if (!window.XMLHttpRequest) {
                $message.append('<iframe class="messageIframe"><\/iframe>');
            }
            $message.appendTo("body");
        }
        
        $message.children("div").removeClass("messagewarnIcon messageerrorIcon messagesuccessIcon").addClass

("message" + message.type + "Icon").html(message.content);
        $message.css({"margin-left": - parseInt($message.outerWidth() / 2), "z-index": zIndex ++}).show();
        
        clearTimeout(messageTimer);
        messageTimer = setTimeout(function() {
            $message.hide();
        }, 3000);
        return $message;
    };
    // 对话框
    $.dialog1 = function(options) {
        var settings = {
            width: 320,
            height: "auto",
            modal: true,
            title: "",
            ok: message("admin.dialog.ok"),
            cancel: message("admin.dialog.cancel"),
            onShow: null,
            onClose: null,
            onOk: null,
            onCancel: null
        };
        $.extend(settings, options);
        
        if (settings.content == null) {
            return false;
        }
        
        var $dialog = $('<div class="xxDialog"><\/div>');
        var $dialogTitle;
        var $dialogClose = $('<div class="dialogClose"><\/div>').appendTo($dialog);
        var $dialogContent;
        var $dialogBottom;
        var $dialogOk;
        var $dialogCancel;
        var $dialogOverlay;
        if (settings.title != null) {
            $dialogTitle = $('<div class="dialogTitle"><\/div>').appendTo($dialog);
        }
        if (settings.type != null) {
            $dialogContent = $('<div class="dialogContent dialog' + settings.type + 'Icon"><\/div>').appendTo($dialog);
        } else {
            $dialogContent = $('<div class="dialogContent"><\/div>').appendTo($dialog);
        }
        if (settings.ok != null || settings.cancel != null) {
            $dialogBottom = $('<div class="dialogBottom"><\/div>').appendTo($dialog);
        }
        if (settings.ok != null) {
            $dialogOk = $('<input type="button" class="input_button_2" value="' + settings.ok + '" \/>').appendTo($dialogBottom);
        }
        if (settings.cancel != null) {
            $dialogCancel = $('<input type="button" class="input_button_2" value="' + settings.cancel + '" \/>').appendTo($dialogBottom);
        }
        if (!window.XMLHttpRequest) {
            $dialog.append('<iframe class="dialogIframe"><\/iframe>');
        }
        $dialog.appendTo("body");
        if (settings.modal) {
            $dialogOverlay = $('<div class="dialogOverlay"><\/div>').insertAfter($dialog);
        }
        
        var dialogX;
        var dialogY;
        if (settings.title != null) {
            $dialogTitle.text(settings.title);
        }
        $dialogContent.html(settings.content);
        $dialog.css({"width": settings.width, "height": settings.height, "margin-left": - parseInt(settings.width / 2), "z-index": zIndex ++});
        dialogShow();
        
        if ($dialogTitle != null) {
            $dialogTitle.mousedown(function(event) {
                $dialog.css({"z-index": zIndex ++});
                var offset = $(this).offset();
                if (!window.XMLHttpRequest) {
                    dialogX = event.clientX - offset.left;
                    dialogY = event.clientY - offset.top;
                } else {
                    dialogX = event.pageX - offset.left;
                    dialogY = event.pageY - offset.top;
                }
                $("body").bind("mousemove", function(event) {
                    $dialog.css({"top": event.clientY - dialogY, "left": event.clientX - dialogX, "margin": 0});
                });
                return false;
            }).mouseup(function() {
                $("body").unbind("mousemove");
                return false;
            });
        }
        
        if ($dialogClose != null) {
            $dialogClose.click(function() {
                dialogClose();
                return false;
            });
        }
        
        if ($dialogOk != null) {
            $dialogOk.click(function() {
                if (settings.onOk && typeof settings.onOk == "function") {
                    if (settings.onOk($dialog) != false) {
                        dialogClose();
                    }
                } else {
                    dialogClose();
                }
                return false;
            });
        }
        
        if ($dialogCancel != null) {
            $dialogCancel.click(function() {
                if (settings.onCancel && typeof settings.onCancel == "function") {
                    if (settings.onCancel($dialog) != false) {
                        dialogClose();
                    }
                } else {
                    dialogClose();
                }
                return false;
            });
        }
        
        function dialogShow() {
            if (settings.onShow && typeof settings.onShow == "function") {
                if (settings.onShow($dialog) != false) {
                    $dialog.show();
                    $dialogOverlay.show();
                }
            } else {
                $dialog.show();
                $dialogOverlay.show();
            }
        }
        function dialogClose() {
            if (settings.onClose && typeof settings.onClose == "function") {
                if (settings.onClose($dialog) != false) {
                    $dialogOverlay.remove();
                    $dialog.remove();
                }
            } else {
                $dialogOverlay.remove();
                $dialog.remove();
            }
        }
        return $dialog;
    }
    // 对话框
    $.dialog2 = function(options) {
        var settings = {
            width: 320,
            height: "auto",
            modal: true,
            title: "",
            ok: message("admin.dialog.ok"),
            cancel: message("admin.dialog.cancel"),
            onShow: null,
            onClose: null,
            onOk: null,
            onCancel: null
        };
        $.extend(settings, options);
        
        if (settings.content == null) {
            return false;
        }
        
        var $dialog = $('<div class="xxDialog"><\/div>');
        var $dialogTitle;
        var $dialogClose = $('<div class="dialogClose"><\/div>').appendTo($dialog);
        var $dialogContent;
        var $dialogBottom;
        var $dialogOk;
        var $dialogCancel;
        var $dialogOverlay;
        if (settings.title != null) {
            $dialogTitle = $('<div class="dialogTitle"><\/div>').appendTo($dialog);
        }
        if (settings.type != null) {
            $dialogContent = $('<div class="dialogContent dialog' + settings.type + 'Icon"><\/div>').appendTo($dialog);
        } else {
            $dialogContent = $('<div class="dialogContent"><\/div>').appendTo($dialog);
        }
        if (settings.ok != null || settings.cancel != null) {
            $dialogBottom = $('<div class="dialogBottom"><\/div>').appendTo($dialog);
        }
        if (settings.ok != null) {
            $dialogOk = $('<input type="button" style="width:100px; margin-right: 20px;" value="' + settings.ok + '" \/>').appendTo($dialogBottom);
        }
        if (settings.cancel != null) {
            $dialogCancel = $('<input type="button" style="width:80px" value="' + settings.cancel + '" \/>&nbsp;&nbsp;').appendTo($dialogBottom);
        }
        if (!window.XMLHttpRequest) {
            $dialog.append('<iframe class="dialogIframe"><\/iframe>');
        }
        $dialog.appendTo("body");
        if (settings.modal) {
            $dialogOverlay = $('<div class="dialogOverlay"><\/div>').insertAfter($dialog);
        }
        
        var dialogX;
        var dialogY;
        if (settings.title != null) {
            $dialogTitle.text(settings.title);
        }
        $dialogContent.html(settings.content);
        $dialog.css({"width": settings.width, "height": settings.height, "margin-left": - parseInt(settings.width / 2), "z-index": zIndex ++});
        dialogShow();
        
        if ($dialogTitle != null) {
            $dialogTitle.mousedown(function(event) {
                $dialog.css({"z-index": zIndex ++});
                var offset = $(this).offset();
                if (!window.XMLHttpRequest) {
                    dialogX = event.clientX - offset.left;
                    dialogY = event.clientY - offset.top;
                } else {
                    dialogX = event.pageX - offset.left;
                    dialogY = event.pageY - offset.top;
                }
                $("body").bind("mousemove", function(event) {
                    $dialog.css({"top": event.clientY - dialogY, "left": event.clientX - dialogX, "margin": 0});
                });
                return false;
            }).mouseup(function() {
                $("body").unbind("mousemove");
                return false;
            });
        }
        
        if ($dialogClose != null) {
            $dialogClose.click(function() {
                dialogClose();
                return false;
            });
        }
        
        if ($dialogOk != null) {
            $dialogOk.click(function() {
                if (settings.onOk && typeof settings.onOk == "function") {
                    if (settings.onOk($dialog) != false) {
                        dialogClose();
                    }
                } else {
                    dialogClose();
                }
                return false;
            });
        }
        
        if ($dialogCancel != null) {
            $dialogCancel.click(function() {
                if (settings.onCancel && typeof settings.onCancel == "function") {
                    if (settings.onCancel($dialog) != false) {
                        dialogClose();
                    }
                } else {
                    dialogClose();
                }
                return false;
            });
        }
        
        function dialogShow() {
            if (settings.onShow && typeof settings.onShow == "function") {
                if (settings.onShow($dialog) != false) {
                    $dialog.show();
                    $dialogOverlay.show();
                }
            } else {
                $dialog.show();
                $dialogOverlay.show();
            }
        }
        function dialogClose() {
            if (settings.onClose && typeof settings.onClose == "function") {
                if (settings.onClose($dialog) != false) {
                    $dialogOverlay.remove();
                    $dialog.remove();
                }
            } else {
                $dialogOverlay.remove();
                $dialog.remove();
            }
        }
        return $dialog;
    }
    // 对话框
    $.dialog = function(options) {
        var settings = {
            width: 320,
            height: "auto",
            modal: true,
            title: "",
            ok: message("admin.dialog.ok"),
            cancel: message("admin.dialog.cancel"),
            onShow: null,
            onClose: null,
            onOk: null,
            onCancel: null
        };
        $.extend(settings, options);
        
        if (settings.content == null) {
            return false;
        }
        
        var $dialog = $('<div class="xxDialog"><\/div>');
        var $dialogTitle;
        var $dialogClose = $('<div class="dialogClose"><\/div>').appendTo($dialog);
        var $dialogContent;
        var $dialogBottom;
        var $dialogOk;
        var $dialogCancel;
        var $dialogOverlay;
        if (settings.title != null) {
            $dialogTitle = $('<div class="dialogTitle"><\/div>').appendTo($dialog);
        }
        if (settings.type != null) {
            $dialogContent = $('<div class="dialogContent dialog' + settings.type + 'Icon"><\/div>').appendTo($dialog);
        } else {
            $dialogContent = $('<div class="dialogContent"><\/div>').appendTo($dialog);
        }
        if (settings.ok != null || settings.cancel != null) {
            $dialogBottom = $('<div class="dialogBottom"><\/div>').appendTo($dialog);
        }
        if (settings.ok != null) {
            $dialogOk = $('<input type="button" class="input_button_3" value="' + settings.ok + '" \/>').appendTo($dialogBottom);
        }
        if (settings.cancel != null) {
            $dialogCancel = $('<input type="button" class="input_button_3" value="' + settings.cancel + '" \/>').appendTo($dialogBottom);
        }
        if (!window.XMLHttpRequest) {
            $dialog.append('<iframe class="dialogIframe"><\/iframe>');
        }
        $dialog.appendTo("body");
        if (settings.modal) {
            $dialogOverlay = $('<div class="dialogOverlay"><\/div>').insertAfter($dialog);
        }
        
        var dialogX;
        var dialogY;
        if (settings.title != null) {
            $dialogTitle.text(settings.title);
        }
        $dialogContent.html(settings.content);
        $dialog.css({"width": settings.width, "height": settings.height, "margin-left": - parseInt(settings.width / 2), "z-index": zIndex ++});
        dialogShow();
        
        if ($dialogTitle != null) {
            $dialogTitle.mousedown(function(event) {
                $dialog.css({"z-index": zIndex ++});
                var offset = $(this).offset();
                if (!window.XMLHttpRequest) {
                    dialogX = event.clientX - offset.left;
                    dialogY = event.clientY - offset.top;
                } else {
                    dialogX = event.pageX - offset.left;
                    dialogY = event.pageY - offset.top;
                }
                $("body").bind("mousemove", function(event) {
                    $dialog.css({"top": event.clientY - dialogY, "left": event.clientX - dialogX, "margin": 0});
                });
                return false;
            }).mouseup(function() {
                $("body").unbind("mousemove");
                return false;
            });
        }
        
        if ($dialogClose != null) {
            $dialogClose.click(function() {
                dialogClose();
                return false;
            });
        }
        
        if ($dialogOk != null) {
            $dialogOk.click(function() {
                if (settings.onOk && typeof settings.onOk == "function") {
                    if (settings.onOk($dialog) != false) {
                        dialogClose();
                    }
                } else {
                    dialogClose();
                }
                return false;
            });
        }
        
        if ($dialogCancel != null) {
            $dialogCancel.click(function() {
                if (settings.onCancel && typeof settings.onCancel == "function") {
                    if (settings.onCancel($dialog) != false) {
                        dialogClose();
                    }
                } else {
                    dialogClose();
                }
                return false;
            });
        }
        
        function dialogShow() {
            if (settings.onShow && typeof settings.onShow == "function") {
                if (settings.onShow($dialog) != false) {
                    $dialog.show();
                    $dialogOverlay.show();
                }
            } else {
                $dialog.show();
                $dialogOverlay.show();
            }
        }
        function dialogClose() {
            if (settings.onClose && typeof settings.onClose == "function") {
                if (settings.onClose($dialog) != false) {
                    $dialogOverlay.remove();
                    $dialog.remove();
                }
            } else {
                $dialogOverlay.remove();
                $dialog.remove();
            }
        }
        return $dialog;
    }
    $.openLoading = function() {
        var sWidth, sHeight;
        sWidth = window.screen.availWidth;
        if (window.screen.availHeight > document.body.scrollHeight)
        {
            sHeight = window.screen.availHeight;

        } else
        {
            sHeight = document.body.scrollHeight + 20;

        }
        //遮罩div
        var maskObj = document.createElement("div");
        maskObj.setAttribute('id', 'BigDiv02');
        maskObj.style.position = "absolute";
        maskObj.style.top = "0";
        maskObj.style.left = "0";
        maskObj.style.background = "#f7f7f7";
        maskObj.style.filter = "Alpha(opacity=70);";
        maskObj.style.opacity = "0.7";
        maskObj.style.width = sWidth + "px";
        maskObj.style.height = sHeight + "px";
        maskObj.style.zIndex = "1000000";
        $("body").attr("style", "overflow:hidden");
        document.body.appendChild(maskObj);
        //$("#BigDiv02").data("divbox_selectlist", $("select:visible"));
        //$("select:visible").hide();
        $("#BigDiv02").attr("divbox_scrolltop", $.ScrollPosition01().Top);
        $("#BigDiv02").attr("divbox_scrollleft", $.ScrollPosition01().Left);
        $("#BigDiv02").attr("htmloverflow", $("html").css("overflow"));
        $("html").css("overflow", "hidden");

       
        var Loading = document.createElement("div");
        
        Loading.setAttribute('class', 'newLoading');
        Loading.setAttribute('id', 'newLoading');
        document.body.appendChild(Loading);
        
        var MyDiv_w = 45;
        var MyDiv_h = 45;
        MyDiv_w = parseInt(MyDiv_w);
        MyDiv_h = parseInt(MyDiv_h);
        var width = $.PageSize01().Width;
        var height = $.PageSize01().Height;
        var left = $.ScrollPosition01().Left;
        var top = $.ScrollPosition01().Top;
        var Div_topposition = top + (height / 2) - (MyDiv_h / 2);
        var Div_leftposition = left + (width / 2) - (MyDiv_w / 2);
        
        $("#newLoading").css({'position':'absolute', 'z-index':'1000001','left':Div_leftposition+"px",'top':Div_topposition + "px",'background-image':"url('images/loading.gif')",'width':'32px','height':'32px'});
        window.scrollTo($("#BigDiv02").attr("divbox_scrollleft"), $("#BigDiv02").attr("divbox_scrolltop"));
       

    };
    $.closeLoading = function()
    {
        $("body").attr("style", "overflow-y:auto");
        window.scrollTo($("#BigDiv02").attr("divbox_scrollleft"), $("#BigDiv02").attr("divbox_scrolltop"));
        //$("#BigDiv02").data("divbox_selectlist").show();
        $("#BigDiv02").remove();
        $("#newLoading").remove();

    }
    
    $.validate = function(obj) {
        
        if(obj != null){
            if("fail"==obj.result){
                $.message("error", "系统错误,请联系管理员");
                return true;
            }
            if("error"==obj.result&&""!=obj.message){
                $.message("error", obj.message);
                return true;
            }
            if("success"==obj.result&&""!=obj.message){
                $.message("success", obj.message);
                return false;
            }
            
            return false;
        }else{
            return false;
        }
        
    };
    
    $.PageSize01 = function() {
             var width=0;
            var height=0;
            width=window.innerWidth!=null?

window.innerWidth:document.documentElement&&document.documentElement.clientWidth?

document.documentElement.clientWidth:document.body!=null?document.body.clientWidth:null;
            height=window.innerHeight!=null?

window.innerHeight:document.documentElement&&document.documentElement.clientHeight?

document.documentElement.clientHeight:document.body!=null?document.body.clientHeight:null;
            return {Width:width,Height:height};
    };
    $.ScrollPosition01 = function() {
        var top=0,left=0;
        
        if($.browser.mozilla)
        {
            top=window.pageYOffset;
            left=window.pageXOffset;
            
        }
        else if($.browser.msie)
        {
            top=document.documentElement.scrollTop;
            left=document.documentElement.scrollLeft;

        }
        else if(document.body)
        {
            top=document.body.scrollTop;
            left=document.body.scrollLeft;
        }
        return {Top:top,Left:left};
        
    };
})(jQuery);

function returnFloat(value){//保留两位小数不足补零
     if(value==undefined || value==null || value ==''){
         return '';
     }
     var value=Math.round(parseFloat(value)*100)/100;
     var xsd=value.toString().split(".");
     if(xsd.length==1){
         value=value.toString()+".00";
         return value;
     }
     
     if(xsd.length>1){
         if(xsd[1].length<2){
             value=value.toString()+"0";
         }
     return value;
     }
}

//小数点. 后面只能保留2位小数
function regNum(value){
    var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
    var flag= reg.test(value);
    return !flag;
}
/**
*身份证验证
*/
function identityCodeValid(code,id){
    var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
    var tip = "";
    var pass= true;
    if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
        tip = "身份证信息不正确";
        pass = false;
    }else if(!city[code.substr(0,2)]){
        tip = "身份证信息不正确";
        pass = false;
    }else{
        //18位身份证需要验证最后一位校验位
        if(code.length == 18){
            code = code.split('');
            //∑(ai×Wi)(mod 11)
            //加权因子
            var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
            //校验位
            var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
            var sum = 0;
            var ai = 0;
            var wi = 0;
            for (var i = 0; i < 17; i++)
            {
                ai = code[i];
                wi = factor[i];
                sum += ai * wi;
            }
            var last = parity[sum % 11];
            if(parity[sum % 11] != code[17]){
                tip = "身份证信息不正确";
                pass =false;
            }
        }
    }
    if(!pass){
        if(id==undefined||id==''){
            $.message("error",tip);
        }else{
            $('#'+id).css('border','1px solid red');
            $('#'+id).poshytip('update', tip);
            $('#'+id).poshytip('show'); 
        }
    } 
    return pass;
}
/**
*身份证验证(返回值)
*/
function identityCodeValidToBack(code){ 
    var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
    var tip = "";
    var pass= true;
    if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
        tip = "身份证信息不正确";
        pass = false;
    }else if(!city[code.substr(0,2)]){
        tip = "身份证信息不正确";
        pass = false;
    }else{
        //18位身份证需要验证最后一位校验位
        if(code.length == 18){
            code = code.split('');
            //∑(ai×Wi)(mod 11)
            //加权因子
            var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
            //校验位
            var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
            var sum = 0;
            var ai = 0;
            var wi = 0;
            for (var i = 0; i < 17; i++)
            {
                ai = code[i];
                wi = factor[i];
                sum += ai * wi;
            }
            var last = parity[sum % 11];
            if(parity[sum % 11] != code[17]){
                tip = "身份证信息不正确";
                pass =false;
            }
        }
    }
    return pass;
}
/**
*金额转换为xxx,xxx.00形式
*/
function fmoney(s){  
    if(s==undefined||s==null||s==''||isNaN(s)) return "0.00";
    var strs = Number(s).toFixed(2).split(".");
    var preStrs = strs[0].split("").reverse();
    var ss="";
    for(j=0;j<preStrs.length;j++){
        ss += preStrs[j] + ((j+1)%3==0&&(j+1)!=preStrs.length?",":"");
    }
    return ss.split("").reverse().join("")+"."+strs[1];
}
//加载控件
$.loading = function(options) {
	var settings = {
		width: 320,
		height: 80,
		content:"加载中...",
		modal: false
	};
	$.extend(settings, options);
	var $dialog;
	if($(" .loading").length > 0){
		return this;
	}else{
		$dialog = $('<div class="loading"><\/div>');
	}
	//是否有按钮
	
	$dialogContent = $('<div class="dialogContent"><\/div>').appendTo($dialog);
	$dialogContent.html("<div class='loadingdiv'><span class='loadingIco'></span><span class='loadingContent'>"+settings.content+"</span></div>");
	
	
	if (!window.XMLHttpRequest) {
		$dialog.append('<iframe class="sdialogIframe"><\/iframe>');
	}
	$dialog.appendTo("body");
	//是否遮罩
	$dialogOverlay = $('<div class="loadingOverlay"><\/div>').insertAfter($dialog);
	
	
	var dialogX;
	var dialogY;
	
	$dialog.css({"width": settings.width, "height": settings.height, "margin-left": - parseInt(settings.width / 2), "z-index": zIndex});
	dialogShow();
	
	
	function dialogShow() {
		$dialog.show();
		if(settings.modal){
			$dialogOverlay.show();
		}
	}
	$dialog.close = function () {
		dialogClose();
	}	
	$dialog.content = function (content) {
		this.find(" .loadingContent").html(content);
	}
	function dialogClose() {
		if (settings.onClose && typeof settings.onClose == "function") {
			if (settings.onClose($dialog) != false) {
				if(settings.modal){
					$dialogOverlay.remove();
				}
				
				$dialog.remove();
			}
		} else {
			if(settings.modal){
					$dialogOverlay.remove();
			}
			$dialog.remove();
		}
	}
	return $dialog;
} 
/**
 * openLoading bug 修改 用于激活卡
 */
$.openLoading_jhk = function() {
    var sWidth, sHeight;
    sWidth = window.screen.availWidth;
    if (window.screen.availHeight > document.body.scrollHeight)
    {
        sHeight = window.screen.availHeight;
    } else
    {
        sHeight = document.body.scrollHeight + 20;
    }
    //遮罩div
    var maskObj = document.createElement("div");
    maskObj.setAttribute('id', 'BigDiv02');
    maskObj.style.position = "absolute";
    maskObj.style.top = "0";
    maskObj.style.left = "0";
    maskObj.style.background = "#f7f7f7";
    maskObj.style.filter = "Alpha(opacity=70);";
    maskObj.style.opacity = "0.7";
    maskObj.style.width = sWidth + "px";
    maskObj.style.height = sHeight + "px";
    maskObj.style.zIndex = "1000000";
    document.body.appendChild(maskObj);
    
    $("body").css("overflow", "hidden");
    
    $("#BigDiv02").attr("divbox_scrolltop", $.ScrollPosition01().Top);
    $("#BigDiv02").attr("divbox_scrollleft", $.ScrollPosition01().Left);
    
    /*if (document.documentElement.scrollTop) {
    	document.documentElement.scrollTo($("#BigDiv02").attr("divbox_scrollleft"), $("#BigDiv02").attr("divbox_scrolltop"))
    } else if (document.body.scrolltop) {
    	document.body.scrollTo($("#BigDiv02").attr("divbox_scrollleft"), $("#BigDiv02").attr("divbox_scrolltop"))
    } */
    // document.body.scrollTo($("#BigDiv02").attr("divbox_scrollleft"), $("#BigDiv02").attr("divbox_scrolltop"));
    var body
    if (document.documentElement) {
    	body = document.documentElement
    } else {
    	body = document.body
    }
    // $(window).scrollTop($("#BigDiv02").attr("divbox_scrollleft"), $("#BigDiv02").attr("divbox_scrolltop"))
    $(body).scrollLeft($("#BigDiv02").attr("divbox_scrollleft")) 
    $(body).scrollTop($("#BigDiv02").attr("divbox_scrolltop"))
    
    var Loading = document.createElement("div");
    Loading.setAttribute('class', 'newLoading');
    Loading.setAttribute('id', 'newLoading');
    document.body.appendChild(Loading);
    $("#newLoading").css({'position':'fixed', 'z-index':'1000001','left': '50%','top': '50%','background-image':"url('images/loading.gif')",'width':'32px','height':'32px', 'margin-left': '-16px', 'margin-top': '-16px'});
    
};
// jhk 弹窗 --------------------------start
/**
 * 激活卡 信息弹窗弹窗
 * data
 * data.type 'success'/'error'/
 * data.title 标题
 * data.contant 内容 
 * data.btnArr 按钮 [{name: 'XXX', func: function(){}]
 */
// $.openMessage = function(data) {
(function (jq) {
    $.extend({
        'openMessage': function(data) {
            if ($('#message').length != 0) {
                return
            }
            var sWidth, sHeight;
            sWidth = window.screen.availWidth;
            if (window.screen.availHeight > document.body.scrollHeight)
            {
                sHeight = window.screen.availHeight;
        
            } else
            {
                sHeight = document.body.scrollHeight + 20;
        
            }
            //遮罩div
            var maskObj = document.createElement("div");
            maskObj.setAttribute('id', 'BigDiv02');
            maskObj.style.position = "absolute";
            maskObj.style.top = "0";
            maskObj.style.left = "0";
            maskObj.style.background = "rgb(17, 17, 17)";
            maskObj.style.filter = "Alpha(opacity=70);";
            maskObj.style.opacity = "0.7";
            maskObj.style.width = sWidth + "px";
            maskObj.style.height = sHeight + "px";
            maskObj.style.zIndex = "1000000";
            $("html").css("overflow", "hidden");
            document.body.appendChild(maskObj);
            $("#BigDiv02").attr("divbox_scrolltop", $.ScrollPosition01().Top);
            $("#BigDiv02").attr("divbox_scrollleft", $.ScrollPosition01().Left);
            $("#BigDiv02").attr("htmloverflow", $("html").css("overflow"));
            
            var message = document.createElement("message");
            message.setAttribute('class', 'message');
            message.setAttribute('id', 'message');
            document.body.appendChild(message);
            
            // 关闭按钮
            setMessageCloseBtn()
            
            // 图标
            if (data.type) {
                setMessageTypeImg(data.type)
            }
           
            // 标题
            if (data.title) {
                setMassageTitle(data.title)
            }
            
            // 内容
            if (data.contant) {
                setMassageContainer(data.contant)
            }
            
            // 按钮
            if (data.btnArr) {
                setMessageButton(data.btnArr)
            }
            
            // 显示弹窗
            $("#message").css({'position':'fixed', 'z-index':'1000001','left': '50%','top': '50%','background':"#fff",'width':'400px', 'margin-left': '-200px'});
        
            // 自动调整高度
            var height = $('#message').outerHeight()
            $("#message").css({'height': height, 'margin-top': -height/2})
            
            window.scrollTo($("#BigDiv02").attr("divbox_scrollleft"), $("#BigDiv02").attr("divbox_scrolltop"));
        
        }
    })
})(jQuery)
// 弹窗 图标
function setMessageTypeImg(type) {
    if (type === 'success') {
        $('#message').append('<div class="message_img"><img src="images/jhk_msg.png" width="50px" height="50px"></div>')
    } else if (type === 'error') {
        $('#message').append('<div class="message_img"><img src="images/jhk_err.png" width="50px" height="50px"></div>')
    }
    $('.message_img').css({'text-align': 'center', 'margin': '20px'})
}
// 弹窗 关闭按钮
function setMessageCloseBtn() {
    $('#message').append('<div class="message_close"></div>')
    $('.message_close').css({'position': 'absolute', 'right': '-50px', 'top': '5px', 'width': '30px', 'height': '30px', 'background': 'url(images/jhk_close2.png)', 'background-size': 'cover'})
    $('.message_close').click(function () {
        $.closeMessage()
    })
}
// 弹窗 标题部分
function setMassageTitle(title) {
    // title 长度最长为20
    $('#message').append('<div class="message_title">' + title.substr(0, 20) + '</div><div class="message_close"></div>')
    $('.message_title').css({'height': '60px', 'text-align': 'center', 'line-height': '60px', 'font-size': '28px', 'border-bottom': '1px solid #1296db', 'font-weight': '700', 'margin': '0 30px'})
}
// 内容部分
function setMassageContainer(contant) {
    $('#message').append('<div class="message_container">' + contant + '</div>')
    $('.message_container').css({'padding': '20px 30px 40px', 'font-size': '16px'})
}
// 底部
function setMessageButton(btnArr) {
    $('#message').append('<div class="message_btns"></div>')
    $('.message_btns').css({'text-align': 'right', 'margin': '10px 20px', 'cursor': 'pointer'})
    $.each(btnArr, function (i, v) {
        $('.message_btns').append('<span class="message_btn" id="message_btn' + i + '">' + v.name + '</span>')
        $('#message_btn' + i).click(v.func)
    })
    $('.message_btn').css({'padding': '10px 20px', 'border': '1px solid #ccc', 'line-height': '30px', 'margin-right': '20px'})
    $('.message_btn').mouseover(function(){
        $(this).css({'background': '#1296db', 'color': '#fff'})
    })
    $('.message_btn').mouseout(function(){
        $(this).css({'background': 'transparent', 'color': '#000'})
    })
}
// 关闭弹窗
$.closeMessage = function () {
    $('#BigDiv02').remove()
    $('#message').remove()
}

//jhk 弹窗 --------------------------end